package com.camerax.sample.base

import android.os.Bundle
import androidx.annotation.LayoutRes
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import com.camerax.sample.BR

/**
 * date        ：2020/11/30
 * author      ：秦川小将
 * description ：
 */
abstract class BaseActivity<T : ViewDataBinding>: AppCompatActivity() {

    protected lateinit var binding: T

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DataBindingUtil.setContentView(this, layoutResId())
        binding.setVariable(BR.data, this)
        binding.lifecycleOwner = this
        initView()
        loadData()
    }

    override fun onDestroy() {
        super.onDestroy()
        binding.unbind()
    }

    /**
     * 初始化Layout
     */
    @LayoutRes
    protected abstract fun layoutResId(): Int

    /**
     * 初始化View
     */
    protected abstract fun initView()

    /**
     * 初始化数据
     */
    protected abstract fun loadData()
}